package com.onluy.frameworkcloud.tools.spring;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextHolder implements ApplicationContextAware {

    public SpringContextHolder() {
    }

    public void setApplicationContext(ApplicationContext context) throws BeansException {
        setContext(context);
    }

    private static void setContext(ApplicationContext context) {
        applicationContext = context;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBean(String name) {
        return applicationContext.getBean(name);
    }

    public static Object getBean(Class requiredType) {
        return applicationContext.getBean(requiredType);
    }

    public static Object getBean(String name, Class clazz) {
        return applicationContext.getBean(name, clazz);
    }

    public static boolean containsBean(String name) {
        return applicationContext.containsBean(name);
    }

    public static String getProperty(String name) {
        return applicationContext.getEnvironment().getProperty(name);
    }

    private static ApplicationContext applicationContext;
}
